package com.qzsoft.zhjd.materiel.modules.materieldatarecive.dto;

import java.math.BigDecimal;

import com.qzsoft.jeemis.common.annotation.Dict;

import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;

/**
 * @ClassName MaterielReceiveForCategoryDto
 * @Description 按照材料分类统计收料情况
 * @author linhuawei
 * @since 2022-04-21
 */
@Data
public class MaterielReceiveForCategoryDto {

    /**
     * 设备名称
     */
    @Excel(name = "地磅名称", width = 40)
    private String deviceName;

    /**
     * 物料名称
     */
    @Excel(name = "材料类别", width = 20)
    private String materielCategoryName;

    /**
     * 数据类型（采购、销售等）
     */
    private String weightDataType;

    /**
     * 数据类型
     */
    @Excel(name = "收料类型", width = 20)
    @Dict(dictCodeId = "WEIGHT_TYPE", dicCodeField = "weightDataType")
    private String weightDataTypeLabel;

    /**
     * 供应商主键
     */
    @Excel(name = "供应商", width = 40)
    private String supplierName;

    /**
     * 运单数量
     */
    @Excel(name = "运单数量", type = 10, width = 16)
    private BigDecimal waybillQuantity;

    /**
     * 实际数量
     */
    @Excel(name = "实际数量", type = 10, width = 16)
    private BigDecimal quantity;

    /**
     * 偏差数量
     */
    @Excel(name = "数量偏差", type = 10, width = 16)
    private BigDecimal deviationQuantity;

    /**
     * 运单重量/t
     */
    @Excel(name = "运单重量(吨)", type = 10, width = 16)
    private BigDecimal waybillWeight;

    /**
     * 实际重量
     */
    @Excel(name = "实际重量(吨)", type = 10, width = 16)
    private BigDecimal weight;

    /**
     * 偏差重量
     */
    @Excel(name = "重量偏差", type = 10, width = 16)
    private BigDecimal deviation;

    /**
     * 偏差比例
     */
    @Excel(name = "重量偏差率(%)", type = 10, width = 16)
    private BigDecimal deviationRatio;

    public BigDecimal getDeviation() {
        if (null != weight && null != waybillWeight) {
            deviation = weight.subtract(waybillWeight);
        }
        return deviation;
    }

    public BigDecimal getDeviationQuantity() {
        if (null != quantity && null != waybillQuantity) {
            deviationQuantity = quantity.subtract(waybillQuantity);
        }
        return deviationQuantity;
    }

    public BigDecimal getDeviationRatio() {
        BigDecimal deviation = getDeviation();
        if (null != deviation && null != waybillWeight && 1 == waybillWeight.compareTo(BigDecimal.ZERO)) {
            if (-1 == deviation.compareTo(BigDecimal.ZERO)) {
                deviationRatio = deviation.abs().multiply(new BigDecimal(100)).divide(waybillWeight, 2,
                        BigDecimal.ROUND_HALF_UP);
            }
        }
        return deviationRatio;
    }

}
